package com.credit.util;

import com.credit.entity.CreditLoanOrder;
import com.credit.entity.CreditUserInfo;
import com.credit.service.UserService;
import com.sun.org.apache.bcel.internal.classfile.Code;

import net.sf.json.JSONObject;

public class PositionUtil {
	
	
	public static  String getPosition(CreditLoanOrder loanOrder){
		
		String position = "";
		
		if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_OFFICE.intValue()){
			JSONObject jsonObject = JSONObject.fromObject(loanOrder.getExtAttribute());
			
			if(jsonObject.get("companyType")!=null&&!"null".equals(jsonObject.get("companyType").toString())){
				int companyType = jsonObject.getInt("companyType"); 
				if(companyType==CodeValueUtil.COMPANYTYPE_INSTITUTION){
					position = "公务员";
				}else if(companyType==CodeValueUtil.COMPANYTYPE_STATECOMPANY){
					position = "国企普通员工";
				}else if(companyType==CodeValueUtil.COMPANYTYPE_TOPFIVEHUNDRED){
					position = "世界500强员工";
				}else if(companyType==CodeValueUtil.COMPANYTYPE_QUOTEDCOMPANY){
					position = "上市公司员工";
				}else if(companyType==CodeValueUtil.COMPANYTYPE_PRIVATEENTERPRISE){
					position = "私企员工";
				}
			}
		
		}else if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_LIBERAL.intValue()){
			position = "自由职业者";
		}else if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_STUDENT.intValue()){
			position = "学生";
		}else if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_PERSONAL.intValue()){
			position = "网店/个体户";
		}else if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_COMPANY.intValue()){
			position = "企业主";
		}
		
		return position;
	}

	public static String getCondition(CreditLoanOrder returnLoadOrder) {
		
		String condition = "";
		
		condition += (returnLoadOrder.getInsurance()!=null)&&(returnLoadOrder.getInsurance().intValue() == CodeValueUtil.HAVE.intValue())?" 有社保，":" 无社保，";
		
		if(returnLoadOrder.getCapital()!=null&&returnLoadOrder.getCapital().intValue() == CodeValueUtil.CAPITAL_CAR.intValue()){
			condition += "有车，";
		}else if(returnLoadOrder.getCapital()!=null&&returnLoadOrder.getCapital().intValue() == CodeValueUtil.CAPITAL_HOUSE.intValue()){
			condition += "有房，";
		}else if(returnLoadOrder.getCapital()!=null&&returnLoadOrder.getCapital().intValue() == CodeValueUtil.CAPITAL_HOUSEANDCAR.intValue()){
			condition += "有房和车，";
		}else{
			condition += "无资产，";
		}
		
		condition += (returnLoadOrder.getMortgage()!=null)&&(returnLoadOrder.getMortgage().intValue() == CodeValueUtil.YES.intValue())?"可抵押":"不可抵押";
		
		return condition;
	}

	public static String getStudentGrade(CreditLoanOrder loanOrder) {
		
		if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_STUDENT.intValue()){
			JSONObject jsonObject = JSONObject.fromObject(loanOrder.getExtAttribute());
			
			if(jsonObject.get("grade")!=null&&!"null".equals(jsonObject.get("grade").toString())){
				return " "+ParamsMapUtil.getLabel("grade", jsonObject.getString("grade"));
			}
			
		}
		
		return "";
	}
	
	public static String getCreditInfo(CreditLoanOrder loanOrder) {
		
		String condition = "";

		if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()!=CodeValueUtil.WORKTYPE_STUDENT.intValue()&&
				loanOrder.getWorkType().intValue()!=CodeValueUtil.WORKTYPE_PERSONAL.intValue()){
			
			condition += (loanOrder.getInsurance()!=null)&&(loanOrder.getInsurance().intValue() == CodeValueUtil.HAVE.intValue())?"有社保   ":"无社保   ";

		}
		
		JSONObject jsonObject = JSONObject.fromObject(loanOrder.getExtAttribute());
		if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_OFFICE.intValue()){
			
			if(jsonObject.get("companyType")!=null&&!"null".equals(jsonObject.get("companyType").toString())){
				int companyType = jsonObject.getInt("companyType"); 
				if(companyType==CodeValueUtil.COMPANYTYPE_STATECOMPANY){
					condition = "有本地社保 ";
					if(jsonObject.get("socialYears")!=null&&!"null".equals(jsonObject.get("socialYears").toString())){
						condition +="连续缴纳"+getSocialYears(jsonObject.getInt("socialYears"));
					}
					
				}else{
					if(jsonObject.get("housingFund")!=null&&!"null".equals(jsonObject.get("housingFund").toString())){
						condition = condition.trim()+(jsonObject.getInt("housingFund") == CodeValueUtil.HAVE.intValue()?"公积金  ":"");
					}
					
				}
			}

			if(jsonObject.get("openSalary")!=null&&!"null".equals(jsonObject.get("openSalary").toString())){
				condition = condition.trim()+" 月打卡工资"+getOpenSalary(jsonObject.getInt("openSalary"));
			}
			
			
			
		}else if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_STUDENT.intValue()){
			
			if(loanOrder.getCreditRecord()!=null){
				condition = condition.trim()+(loanOrder.getCreditRecord().intValue()==CodeValueUtil.CREDITRECORD_NOOVERDUE.intValue()?"信用良好":"有违约现象");
			}
			
			
		    UserService userSerice = (UserService) ApplicationContextUtils.getBean("userService");
			CreditUserInfo userInfo = userSerice.findUserById(loanOrder.getUserId());
			
			condition = condition.trim()+" 芝麻信用"+userInfo.getSesameCredit()+"分";
		
		}else if(loanOrder.getWorkType()!=null&&loanOrder.getWorkType().intValue()==CodeValueUtil.WORKTYPE_PERSONAL.intValue()){
			if(jsonObject.get("annualFlow")!=null&&!"null".equals(jsonObject.get("annualFlow"))){
				condition = condition.trim()+"年流水"+getAnnualFlow(jsonObject.getInt("annualFlow"));
			}
			
		}
		
		if((loanOrder.getCapital()!=null)&&(loanOrder.getCapital().intValue() == CodeValueUtil.CAPITAL_CAR.intValue())){
			condition += " 有车";
		}else if(loanOrder.getCapital()!=null&&loanOrder.getCapital().intValue() == CodeValueUtil.CAPITAL_HOUSE.intValue()){
			condition += " 有房";
		}else if(loanOrder.getCapital()!=null&&loanOrder.getCapital().intValue() == CodeValueUtil.CAPITAL_HOUSEANDCAR.intValue()){
			condition += " 有房和车";
		}
		
		if(loanOrder.getMortgage()!=null){
			condition += loanOrder.getMortgage().intValue() == CodeValueUtil.YES.intValue()?"可抵押":"不可抵押";
		}
		
		
		return condition;
	}

	private static String getAnnualFlow(int annualFlow) {
		
		if(annualFlow==CodeValueUtil.ANNUALFLOW_LT_10_WAN){
			return "不足10w";
		}else if(annualFlow==CodeValueUtil.ANNUALFLOW_10_30_WAN){
			return "10w到30w";
		}else if(annualFlow==CodeValueUtil.ANNUALFLOW_30_50_WAN){
			return "30w到50w";
		}else if(annualFlow==CodeValueUtil.ANNUALFLOW_50_100_WAN){
			return "50w到100w";
		}else if(annualFlow==CodeValueUtil.ANNUALFLOW_100_500_WAN){
			return "100w到500w";
		}else if(annualFlow==CodeValueUtil.ANNUALFLOW_500_1000_WAN){
			return "500w到1000w";
		}else if(annualFlow==CodeValueUtil.ANNUALFLOW_GT_1000_WAN){
			return "1000w以上";
		}
		
		return "";
	}

	private static String getOpenSalary(int openSalary) {
		if(openSalary==CodeValueUtil.OPENSALARY_LT_3500){
			return "不足3500";
		}else if(openSalary==CodeValueUtil.OPENSALARY_3500_5000.intValue()){
			return "3500到5000";
		}else if(openSalary==CodeValueUtil.OPENSALARY_5000_8000.intValue()){
			return "5000到8000";
		}else if(openSalary==CodeValueUtil.OPENSALARY_8000_10000.intValue()){
			return "8000到10000";
		}else if(openSalary==CodeValueUtil.OPENSALARY_10000_15000.intValue()){
			return "10000到15000";
		}else if(openSalary==CodeValueUtil.OPENSALARY_15000_20000.intValue()){
			return "15000到20000";
		}else if(openSalary==CodeValueUtil.OPENSALARY_GT_20000.intValue()){
			return "20000元以上";
		}
		return "";
	}

	private static String getSocialYears(int value) {
		if(value == CodeValueUtil.SOCIALYEARS_LT_3_MONTHS){
			return "不足3个月";
		}else if(value == CodeValueUtil.SOCIALYEARS_3_6_MONTHS){
			return "3个月";
		}else if(value == CodeValueUtil.SOCIALYEARS_6MONTHS_1YEAR){
			return "6个月";
		}else if(value == CodeValueUtil.SOCIALYEARS_1_2_YEAR){
			return "1年";
		}else if(value == CodeValueUtil.SOCIALYEARS_GT_2_YEAR){
			return "2年以上";
		}
		return "";
	}

}
